home *** CD-ROM | disk | FTP | other *** search
/ CD Actual Thematic 7: Programming / CDAT7.iso / demos / VisualAge for Java 2.0 Entry / setup / data1.cab / ide-e / IDE / cache / 16O9IPP (.txt) < prev    next >
Encoding:
Java Class File  |  1998-09-16  |  3.9 KB  |  87 lines

  1. package com.sun.java.swing.plaf.metal;
  2.  
  3. import com.sun.java.swing.AbstractButton;
  4. import com.sun.java.swing.ButtonModel;
  5. import com.sun.java.swing.JComponent;
  6. import com.sun.java.swing.UIManager;
  7. import com.sun.java.swing.plaf.ComponentUI;
  8. import com.sun.java.swing.plaf.basic.BasicButtonListener;
  9. import com.sun.java.swing.plaf.basic.BasicButtonUI;
  10. import com.sun.java.swing.plaf.basic.BasicGraphicsUtils;
  11. import java.awt.Color;
  12. import java.awt.Component;
  13. import java.awt.Dimension;
  14. import java.awt.FontMetrics;
  15. import java.awt.Graphics;
  16. import java.awt.Rectangle;
  17.  
  18. public class MetalButtonUI extends BasicButtonUI {
  19.    private static final MetalButtonUI metalButtonUI = new MetalButtonUI();
  20.  
  21.    protected BasicButtonListener createListener(JComponent c) {
  22.       return new MetalButtonListener((AbstractButton)c);
  23.    }
  24.  
  25.    public static ComponentUI createUI(JComponent c) {
  26.       return metalButtonUI;
  27.    }
  28.  
  29.    protected Color getDisabledTextColor() {
  30.       return UIManager.getColor("Button.disabledText");
  31.    }
  32.  
  33.    protected Color getFocusColor() {
  34.       return UIManager.getColor("Button.focus");
  35.    }
  36.  
  37.    protected Color getSelectColor() {
  38.       return UIManager.getColor("Button.pressed");
  39.    }
  40.  
  41.    public void installUI(JComponent c) {
  42.       super.installUI(c);
  43.       c.setOpaque(true);
  44.    }
  45.  
  46.    protected void paintButtonPressed(Graphics g, AbstractButton b) {
  47.       if (((JComponent)b).isOpaque()) {
  48.          Dimension size = ((Component)b).getSize();
  49.          g.setColor(this.getSelectColor());
  50.          g.fillRect(0, 0, size.width, size.height);
  51.       }
  52.  
  53.    }
  54.  
  55.    protected void paintFocus(Graphics g, AbstractButton b, Rectangle viewRect, Rectangle textRect, Rectangle iconRect) {
  56.       Rectangle focusRect = new Rectangle();
  57.       String text = b.getText();
  58.       boolean isIcon = b.getIcon() != null;
  59.       if (text != null & !text.equals("")) {
  60.          if (!isIcon) {
  61.             focusRect.setBounds(textRect);
  62.          } else {
  63.             focusRect.setBounds(iconRect.union(textRect));
  64.          }
  65.       } else if (isIcon) {
  66.          focusRect.setBounds(iconRect);
  67.       }
  68.  
  69.       g.setColor(this.getFocusColor());
  70.       g.drawRect(focusRect.x - 1, focusRect.y - 1, focusRect.width + 1, focusRect.height + 1);
  71.    }
  72.  
  73.    protected void paintText(Graphics g, JComponent c, Rectangle textRect, String text) {
  74.       AbstractButton b = (AbstractButton)c;
  75.       ButtonModel model = b.getModel();
  76.       FontMetrics fm = g.getFontMetrics();
  77.       if (model.isEnabled()) {
  78.          g.setColor(((Component)b).getForeground());
  79.          BasicGraphicsUtils.drawString(g, text, model.getMnemonic(), textRect.x, textRect.y + fm.getAscent());
  80.       } else {
  81.          g.setColor(UIManager.getColor("Button.disabledText"));
  82.          BasicGraphicsUtils.drawString(g, text, model.getMnemonic(), textRect.x, textRect.y + fm.getAscent());
  83.       }
  84.  
  85.    }
  86. }
  87.